package com.wswy.wzcx.ui.main.garage

import android.graphics.*
import android.support.v4.content.ContextCompat
import com.blankj.utilcode.util.SizeUtils
import com.wswy.wzcx.AppContext
import com.wswy.wzcx.R


class CarsContentDrawable(color: Int) : TipsContentDrawable(color) {

    private val topPaint = Paint(Paint.ANTI_ALIAS_FLAG)

    override fun onBoundsChange(bounds: Rect?) {
        super.onBoundsChange(bounds)
        val gradient = LinearGradient(0f, 0f, rectF.width(), SizeUtils.dp2px(200f).toFloat(),
                intArrayOf(ContextCompat.getColor(AppContext.getContext(), R.color.startColor_1), ContextCompat.getColor(AppContext.getContext(), R.color.endColor_1)), null, Shader.TileMode.CLAMP)

        topPaint.shader = gradient
    }

    override fun draw(canvas: Canvas?) {


        canvas?.run {
            drawRect(0f,
                    0f,
                    intrinsicWidth.toFloat(),
                    SizeUtils.dp2px(200f).toFloat(), topPaint)

            save()
            translate(0f, SizeUtils.dp2px(200f - 40f).toFloat())
            super.draw(canvas)
            restore()
        }


    }


}